package com.kedou.sdk.ui.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.kedou.sdk.ui.assist.OnFinishActivityListener;

/**
 * Created by Administrator on 2018/3/8.
 */

public class CertifiesChooseDialogFragment extends BaseDialogFragment implements View.OnClickListener {


    private RelativeLayout alipayLayout,shoudongLayout;


    public static final CertifiesChooseDialogFragment newInstance(Bundle bundle) {
        CertifiesChooseDialogFragment fragment = new CertifiesChooseDialogFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View contentView = doInflateContentView(inflater, container, getLayoutIdentifier("hnssn_fragment_certifies_choose"));

        alipayLayout = contentView.findViewById(getViewIdentifier("fragment_certifies_alipay"));
        shoudongLayout = contentView.findViewById(getViewIdentifier("fragment_certifies_shoudong"));
        alipayLayout.setOnClickListener(this);
        shoudongLayout.setOnClickListener(this);

//        Bundle bundle = getArguments();
//        if (bundle != null && bundle.containsKey("goods")) {
//            mMessageContent.setText(getStringIdentifier("hnssn_certifies_tip_message"));
//        } else {
//            mMessageContent.setText(getStringIdentifier("hnssn_certifies_tip_guest_message"));
//        }

        return contentView;
    }

    @Override
    public void onClick(View view) {
        if(view == alipayLayout){

            OnAlipayAuthListener listener = getOnAlipayAuthListener();
            if (listener != null) {
                listener.doAlipayAuth();
            }
        }else{
            OnFinishActivityListener listener = getOnFinishActivityListener();
            if (listener != null) {
                listener.doFinishActivity(this);
            }
        }

    }

    private OnAlipayAuthListener getOnAlipayAuthListener() {
        if (!isNullContext()) {
            Activity activity = getActivity();
            if (activity instanceof OnAlipayAuthListener) {
                return (OnAlipayAuthListener) activity;
            }
        }
        return null;
    }

    public interface OnAlipayAuthListener extends OnFinishActivityListener {

        void doAlipayAuth();

    }

    private OnFinishActivityListener getOnFinishActivityListener() {
        if (!isNullContext()) {
            Activity activity = getActivity();
            if (activity instanceof OnFinishActivityListener) {
                return (OnFinishActivityListener) activity;
            }
        }
        return null;
    }
}
